<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
        <title>余额提现</title>
        <link rel="stylesheet" href="<c:url value="/static/wx/css/style.css"/>" />
        <script type="text/javascript" src="<c:url value="/static/wx/js/lib/rem.js"/>"></script>
	</head>
    <body class="befeff4">
        <div id="wrap">
            <div class="wrap_order bf pd60">
                <div class="wrap_select">
                    <div class="wrap_name common_list  mt10">
                        <div class="common boder-bottom relative">
                            <label>到账银行卡</label><input id="name" type="text" disabled="disabled" value="${bankcardInfoVo.bankCardName } (${bankcardInfoVo.bankCardNumber})" placeholder="请填写真实姓名" />
                        </div>
                    </div>

                    <div class="wrap_code common_list">
                        <div class="common boder-bottom relative">
                            <label>提现金额</label>
                            <input id="moneyNum" type="text" value="" placeholder="输入提现金额" onkeyup="clearNoNum(this)" />
                        </div>
                    </div>
                    
                    <input type="hidden" id="amount" value="${accountVo.amount }" />
                    <div class="wrap_code common_list c666 common mt10">
                        最低提现金额为10元；当前可提现金额${accountVo.amount }元
                    </div>
                </div>
                <div class="wrap_btn mt65">
                    <a href="javascript:void(0)" class="button" id="submit_btn">下一步</a>
                </div>
            </div>

            <!--设置成功提示弹窗开始-->
            <div class="msg-succ">
                <img src="<c:url value="/static/wx/img/succ_icon.png"/>" /> <span class="f20">银行卡认证成功</span>
            </div>
            <!--设置成功提示弹窗结束-->

            <!--设置支付密码弹窗-->
            <div class="mask mask_check">
                <div class="msg-succ block c333 f14 bf" style="padding-bottom:0">
                    <div class="f20">提示</div>
                    <p class="mt10">为了保障您的资金安全，请设置支付密码用于后续余额提现或使用</p>
                    <div class="checkTips">
                        <a class="cancel">取消</a>
                        <a class="goCheck" href="checkSetPaymentPassword.html">去认证</a>
                    </div>
                </div>
            </div>

            <!--输入支付密码弹窗开始-->
            <div class="mask mask_pwd">
                <div class="pwd-box">
                    <div id="box-title">
                        <div class="common">
                        <span class="title-text fl tl">请输入支付密码：</span>
                        <span class="cancel fr f20">×</span>
                        </div>
                    </div>
                    <div id="money-box">
                        <div id="money-title" class="common mt10 tc">
                            <span class="title-text">提现金额</span>
                        </div>
                        <div id="money-content" class="tc">
                            <span id="content-text">30.0</span>
                        </div>
                    </div>
                    <div class="relative">
                        <input type="tel" maxlength="6" class="pwd-input" id="pwd-input" onkeyup="value=value.replace(/\D/g,'')">
                        <div class="fake-box">
                            <input type="password" readonly="">
                            <input type="password" readonly="">
                            <input type="password" readonly="">
                            <input type="password" readonly="">
                            <input type="password" readonly="">
                            <input type="password" readonly="">
                        </div>
                    </div>
                    <div>
                        <a id="forget-pwd"  href="<c:url value="/wx/toMdifyPassword.do"/>?userId=${userId}">忘记密码?</a>
                    </div>
                </div>
            </div>
            <!--输入支付密码弹窗结束-->
        </div>

        <input type="hidden" id="userId" value="${userId}" />
        <script type="text/javascript" src="<c:url value="/static/wx/js/lib/jquery-3.3.1.min.js"/>"></script>
        <script type="text/javascript">
            var userId = $("#userId").val();
            $("#submit_btn").on("click", function() {
               var amout = $("#amount").val(); //总金额
               var moneyNum = $("#moneyNum").val().trim(); //提现金额
               var ifSetPassword = true; //假设是否设置支付密码状态 false未设置 true 已设置
               if(!ifSetPassword) {
                   $(".mask_check").slideDown();
               } else {
                   if(!moneyNum) {
                       alert("请输入金额");
                       return false;
                   } else if(parseFloat(amout) < parseFloat(moneyNum)) {
                       alert("余额不足");
                       return false;
                   } else if(moneyNum < 10) {
                       alert("最低提现金额为10元");
                       return false;
                   } else {
                       $('.mask_pwd').slideDown();
                       $("#content-text").text(moneyNum);
                       var $input = $(".fake-box input");
                       $("#pwd-input").on("input", function() {
                           var pwd = $(this).val().trim();
                           for(var i = 0, len = pwd.length; i < len; i++) {
                               $input.eq("" + i + "").val(pwd[i]);
                           }
                           $input.each(function() {
                               var index = $(this).index();
                               if(index >= len) {
                                   $(this).val("");
                               }
                           });
                           
                           if(len == 6) {
                               $('.mask_pwd').slideUp();
                               //提交支付
                               $.ajax({
                            	   type: "POST",
                                   url: "<c:url value="/wx/toPutForward.do"/>",
                                   type: "post",
                                   dataType: "json",
                                   data: {
                                       userId: userId,
                                       password: pwd,
                                       amount : moneyNum,
                                   },
                                   success: function(data) {
                                       if(data.msg == "1") {
                                           $(".msg-succ span").html("提现成功");
                                           $(".msg-succ").show();
                                           var c = 2;
                                           if (data.bankcardInfoVo != null) {
                                        	   var createTime = data.bankcardInfoVo.createTime;
                                        	   var bankCardName = data.bankcardInfoVo.bankCardName;
                                        	   var bankCardNumber = data.bankcardInfoVo.bankCardNumber;
                                        	   var price = data.bankcardInfoVo.price;
                                        	   //返回上一层代码
                                        	   var intervalId = setInterval(function () {
									                c = c - 1;
									                if (c == 0) {
									                  clearInterval(intervalId);
									                  setTimeout(go(userId,createTime,bankCardName,bankCardNumber,price), 1000);
									                }
									           }, 1000)
                                           }
                                       } else if(data.msg == "2") { //支付密码错误，清空输入框
                                    	   alert("密码错误,请重新输入或选择忘记密码");
                                           $("#pwd-input").val("");
                                           $(".fake-box input").each(function() {
                                               $(this).val("");
                                           });
                                           $('.mask_pwd').slideDown();
                                       }
                                   }
                               });
                           }
                       });
                   }
               }
           });
            
           function go(userId,createTime,bankCardName,bankCardNumber,price){
        	    window.location.href = "<c:url value="/wx/toGetCashProgress.do"/>?userId="+userId+"&createTime="+createTime+"&bankCardName="+bankCardName+"&bankCardNumber="+bankCardNumber+"&price="+price;
           }

           $(".cancel").on("click", function() {
               $(".mask").slideUp();
           });

           //js控制input框只能输入数字和一位小数点和小数点后面两位小数
           function clearNoNum(obj) {
               obj.value = obj.value.replace(/[^\d.]/g, ""); //清除“数字”和“.”以外的字符  
               obj.value = obj.value.replace(/\.{2,}/g, "."); //只保留第一个. 清除多余的  
               obj.value = obj.value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
               obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3'); //只能输入两个小数  
               if(obj.value.indexOf(".") < 0 && obj.value != "") { //以上已经过滤，此处控制的是如果没有小数点，首位不能为类似于 01、02的金额 
                   obj.value = parseFloat(obj.value);
               }
           }
        </script>

    </body>
</html>